package entity.lianxi.demo04;

import entity.Student;
import entity.User;

import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Parameter;
import java.util.Map;

/*
* 8.学生*/
public class MainTest04 {
    /*public static void main(String[] args) throws Exception {

        //1.
        Object obj = Array.newInstance(Student.class,2);
        Student stu = new Student();
        stu.setName("张三");
        stu.setAge(15);
        stu.setWeight(12);

        Array.set(obj,0,stu);

        //2.带参
        Student stu1 = new Student("王五",22,14);

        Array.set(obj,1,stu1);

        for ( int i = 0; i < Array.getLength(obj); i++){
            Object o = Array.get(obj, i);
            if (o != null){
                System.out.println(o);
            }
        }
    }*/
    public static void main(String[] args) {
        Class<?> clazz = String.class;
        Method[] methods = clazz.getMethods();


        for (Method method : methods) {
            String name = method.getName();
            String modifiers = Modifier.toString(method.getModifiers());
            String typeName = method.getReturnType().getSimpleName();
            Parameter[] parameters = method.getParameters();
            Class<?>[] types = method.getParameterTypes();
            System.out.print(modifiers + " " + typeName + " " + name);

            // String arg0,int arg1
            System.out.print("(");
            for (Class<?> param : types) {
                for (int i = 0; i < parameters.length; i++) {
                    Parameter parameter = parameters[i];
                    System.out.print(param.getSimpleName() + " " + parameter.getName() + " ");
                    if (i == parameters.length - 1) {
                        System.out.print("");
                    } else {
                        System.out.print(",");
                    }
                }
            }

            System.out.print(")");
            System.out.println();
            System.out.println("方法的个数：" + methods.length);
        }
    }
}
